<?php
class youhui_msg_send{
	public function index(){
		$email = strim($GLOBALS['request']['email']);//用户名或邮箱
		$pwd = strim($GLOBALS['request']['pwd']);//密码
		
		//检查用户,用户密码
		$user = user_check($email,$pwd);
		//print_r($user);die();
		$user_id  = intval($user['id']);	
		$mobile=$user['mobile'];
        if($user['id']<=0)
        {
        	$root['user_login_status'] = 0;
        	$root['info'] = '您还没有登入';
        	$root['return']=0;
        	output($root);	
        }
	    if(empty($user['mobile']))
        {
        	$root['user_mobile'] = 0;
        	$root['info'] = '您的手机号不能为空';
        	$root['return']=0;
        	output($root);	
        }
	
		
		$now = get_gmtime();
		$today_begin = to_timespan(to_date($now,"Y-m-d"));
		$today_end = $today_begin + 24*3600;
		$count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."deal_msg_list where user_id = ".$user['id']." and is_youhui = 1 and create_time between ".$today_begin." and ".$today_end);
    
		if($count>=intval(app_conf("YOUHUI_SEND_LIMIT")))
		{
			 $root['info'] = $GLOBALS['lang']['SMS_LIMIT_OVER'];
			 $root['return']=0;
        	 output($root);	
		}
		else
		{
			$youhui_id = intval($_REQUEST['youhui_id']);
			$youhui_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."youhui where is_effect = 1 and id =".$youhui_id);
			
			if(!$youhui_info)
			{
				$root['info'] = $GLOBALS['lang']['YOUHUI_NO_EXIST'];
			    $root['return']=0;
        	    output($root);	
			}
			
			if($youhui_info['end_time']>0&&$youhui_info['end_time']<get_gmtime())
			{
				$root['info'] = $GLOBALS['lang']['YOUHUI_END_TIME_OVER'];
			    $root['return']=0;
        	    output($root);	
			}
			
			if($youhui_info['is_sms']==0)
			{
				$root['info'] = $GLOBALS['lang']['YOUHUI_NO_SUPPORT_SMS'];
			    $root['return']=0;
        	    output($root);	
			}

				if(send_youhui_sms($youhui_id,$user_id,$mobile))
				{
					$root['info'] = $GLOBALS['lang']['SMS_SEND_SUCCESS'];
			        $root['return']=1;
        	        output($root);	
				}
				else
				{
					$root['info'] = $GLOBALS['lang']['SMS_SEND_FAILED'];
			        $root['return']=0;
        	        output($root);	
				}
		}	
		
	}
}
?>